package database.dbutlis;

import com.alibaba.fastjson.JSON;
import database.utils.DataSourceUtils;
import org.apache.commons.dbutils.QueryRunner;

import java.sql.SQLException;
import java.util.Map;


public class JDBCUtil {

    public static void save(String city){

        Map<String,Object> map = JSON.parseObject(city);

        //创建核心对象
        QueryRunner queryRunner = new QueryRunner(DataSourceUtils.getDataSource());
        //sql语句
        String sql = "insert into attribution values (null,?,?)";
        //执行sql
        try {
            for(Map.Entry<String,Object> entry : map.entrySet()){
                queryRunner.update(sql,entry.getKey(),JSON.toJSONString(entry.getValue()));
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

}
